package priv.stones.service.impl;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import priv.stones.entity.SysRole;
import priv.stones.mapper.SysRoleDao;
import priv.stones.service.SysRoleService;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author: Stones
 * @Description:
 * @Date: 2017-10-16
 */
@Service
public class SysRoleServiceImpl extends ServiceImpl<SysRoleDao, SysRole> implements SysRoleService {

    @Override
    public int relateMenus(String[] menus, String roleID) {
        baseMapper.deleteMenus(roleID);
        if (menus != null) {
            Map<String, String> map = new HashMap<>();
            for (String menu : menus) {
                map.put(menu, roleID);
            }
            baseMapper.insertMenus(map);
            return menus.length;
        }
        return 0;
    }

    @Override
    public List<String> selectMenuIdsById(String roleID) {
        return baseMapper.selectMenuIds(roleID);
    }

    @Override
    public void delete(String roleID) {
        baseMapper.delete(roleID);
    }

}
